<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Tolist</title>
	</head>
	<body>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	
		<div id="root">
			<input type="text" id="" value="" v-model="inputValue" />
			<button type="button" v-on:click="handleBtnclick" >提交</button>
			
			<ul>
				<todo-item 
				v-bind:content="item" 
				v-for="item in list"
				@delete="handleItemDelete"
				></todo-item>
				
			</ul>

		</div>
		<div id="app2">
			
		</div>

	<script type="text/javascript">

		// Vue.component("TodoItem",{
		// 	props:['content'],
		// 	template:"<li>{{content}}</li>"
		// })

		var TodoItem={
			props:['content'],
			template:"<li @click='handleItemClick'>{{content}}</li>",
			methods:{
				handleItemClick:function(){
					// alert("click")
					this.$emit("delete")
				}
			}
		}

		var app=new Vue({
			el:'#root',
			components:{
				TodoItem:TodoItem
			},
			data:{
				list:[],
				inputValue:''
			},
			methods:{
				handleBtnclick:function(){
					this.list.push(this.inputValue)
					this.inputValue=''
				},
				handleItemDelete:function(){
					this.list=[];
				}
			}
		})
	</script>
	</body>
</html>
